//
//  SRCommentView.m
//  SportRing
//
//  Created by icelee on 14-11-1.
//  Copyright (c) 2014年 HotOne. All rights reserved.
//

#import "SRCommentView.h"

@interface SRCommentView()

@property (nonatomic , weak)IBOutlet LGButton *commitButton;
@property (nonatomic , weak)IBOutlet UITextView *commentTextView;


@end

@implementation SRCommentView

- (void)awakeFromNib
{
    [super awakeFromNib];
    
//    [self setupButton];
    _commentTextView.textColor = [UIColor colorWithRed:156 / 255.0 green:156 / 255.0 blue:156 / 255.0 alpha:156 / 255.0];
    self.commitButton.layer.cornerRadius = 4;
    RAC(self.commitButton, enabled) = [RACSignal combineLatest:@[self.commentTextView.rac_textSignal]
                                                    reduce:^(NSString * comment) {
                                                        return @(comment.length > 0);
                                                    }];
    
    @weakify(self);
    [[self.commitButton rac_signalForControlEvents:UIControlEventTouchUpInside]
     subscribeNext:^(id x) {
         [self_weak_.srcDelegate commitComment:self.commentTextView.text];
     }];
}

- (void)setupButton
{
    LGButtonColorPair * disableColor1 = [LGButtonColorPair colorPairWithTitleColor:[UIColor grayColor]
                                                                   backgroundColor:[UIColor colorWithRed:113.0/255.0
                                                                                                   green:183.0/255.0
                                                                                                    blue:20.0/255.0
                                                                                                   alpha:1.0f]];
    LGButtonColorPair * normalColor1 = [LGButtonColorPair colorPairWithTitleColor:[UIColor whiteColor]
                                                                  backgroundColor:[UIColor colorWithRed:113.0/255.0
                                                                                                  green:183.0/255.0
                                                                                                   blue:20.0/255.0
                                                                                                  alpha:1.0f]];
    [self.commitButton setColorPairs:@{@(LG_BUTTON_STATE_TYPE_NORMAL):normalColor1,
                                   @(LG_BUTTON_STATE_TYPE_DISABLED):disableColor1}];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
